package modeller.databasedesignmodel.transaction;

import modeller.databasedesignmodel.Attribute;
import modeller.databasedesignmodel.relation.Relation;
import queped.SerializablePair;

import java.io.Serializable;
import java.util.HashSet;

/**
 * Created by IntelliJ IDEA.
 * User: Jason Ye
 * Date: 21/01/2012
 * Time: 16:25

 */
public abstract class SQLQuery implements ISQLQuery,Serializable {

    private String m_queryString;
    private SerializablePair<Relation, HashSet<Attribute>> relationPair;
    
    public SQLQuery(SerializablePair<Relation, HashSet<Attribute>> relationPair) {
        m_queryString = "";
        this.relationPair = relationPair;
    }


    public void setRelation(Relation r){
        relationPair.setFirst(r);
    }

    @Override
    public SerializablePair<Relation, HashSet<Attribute>> getRelation() {
        return relationPair;
    }

    public void setAttributeList(HashSet<Attribute> attributeSet){
        relationPair.setSecond(attributeSet);
    }

    public void setRelationPair(SerializablePair<Relation, HashSet<Attribute>> relationPair) {
        this.relationPair = relationPair;
    }

    public String getStatement() {
        return m_queryString;
    }

    public void setStatement(String m_statement) {
        this.m_queryString = m_statement;
    }
    
    public abstract String myToString();

    protected String getPrintedAttributeList() {
        StringBuffer buf = new StringBuffer();
        SerializablePair<Relation, HashSet<Attribute>> blah = getRelation();
        HashSet<Attribute> s= blah.second;
        for(Attribute a: s){
            buf.append("\t" + a.getAttributeName() + "\n");
        }

        return buf.toString();
    }

}
